// ==UserScript==
// @name         hyt_weibo
// @namespace    http://tampermonkey.net/
// @version      2024-10-29
// @description  try to take over the world!
// @author       hyt_weibo
// @match       *://*.weibo.com/*
// @icon         
// @require      https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';
    const createButton = (id, text, top) => {
        return $("<div>")
            .attr("id", id)
            .css({
            width: "100px",
            height: "40px",
            background: "#fe2c55",
            position: "fixed",
            top: top + "px",
            left: "140px",
            "z-index": "100000",
            "text-align": "center",
            "line-height": "40px",
            color: "#fff",
            "border-radius": "8px",
            cursor: "pointer",
        }).text(text);
    };
    const scrolnoteButton = createButton("note-scroll", "滚动微博区", 30);
    $("body").append(scrolnoteButton);

    scrolnoteButton.click(() => {
        getplinfo();
    })

    function getplinfo() {
        const result = [];
        const allItems = $(".vue-recycle-scroller__item-view");

        allItems.each(function () {
            const data_index = $(this).find('.wbpro-scroller-item').attr("data-index");
            const name = $(this).find(".ALink_default_2ibt1").attr('aria-label');
            const href = $(this).find(".ALink_default_2ibt1").attr('href');
            const sub_time = $(this).find(".head-info_time_6sFQg").attr('title');
            const info = $(this).find("footer").attr('aria-label');
            const infos = info.split(',');
            const likenum = infos[2];
            const pl = infos[1];
            const trant = infos[0];
            const nowtime = new Date();
            result.push({
                data_index,
                name,
                href,
                sub_time,
                likenum,
                pl,
                trant,
                nowtime:nowtime.toISOString().slice(0, 19).replace('T', ' '),
            });

        });

        console.log(result);
        fetch('http://localhost:3000/api/data',{
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(result),
        })
        .then(response => response.json())
        .then(data => {
            alert('成功', data);
            console.log('成功')
        })
        .catch((error) => {
            alert('失败，请查看控制台报错')
            console.error('错误', error);
        })
        //const excelname = `${window.location.href.split("?")[0]}评论数据.xlsx`;
        //downtoexcel(result, excelname);
    }
    // Your code here...
})();